package com.zyl.Ecs.common.domain.device.ext;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.zyl.Ecs.common.domain.data.bean.DataBean;
import lombok.*;
import lombok.experimental.Accessors;

/**
 * @version v1.0
 * @ProjectName: Ecs
 * @Package: com.zyl.Ecs.common.domain.device.ext
 * @ClassName: SensorEdl
 * @Description TODO (传感器针对类)
 * @Author 翟玉龙
 * @Date 2024/12/9-10:28
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@Builder
public class SensorEdl {
    @JsonProperty("sensorId")
    private Integer sensorId;

    @JsonProperty("exceed")
    private Boolean exceed;

    @JsonProperty("name")
    private String sensorTypeName;

    @JsonProperty("value")
    private String value;

    public static SensorEdl toEdl(SensorExt sensorExt, DataBean dataBean) {
        return SensorEdl.builder()
                .sensorId(sensorExt.getId())
                .exceed(dataBean.getValue() > sensorExt.getTop() || dataBean.getValue() < sensorExt.getLeft())
                .sensorTypeName(sensorExt.getSensorType().getName())
                .value(String.format("%.2f", dataBean.getValue()) + sensorExt.getSensorType().getUnit())
                .build();
    }
}
